// Notice 
//  
// The contents of this file are subject to the
//  same license as the source code for ImageJ.  FracLac is in the public domain.
// If you use it to publish research, please cite the source.
// The initial developer of the original
// code is Audrey Karperien, Charles Sturt University.
package fraclac.FLAnalyzer;
/**Calculates regression statistics on passed arrays or their transformations.
 *   
 * <h3>Inputs:</h3>
 * integer or float arrays, integer for number of values to assess
 * <h3>Outputs:</h3>
 * <p>Regression statistics
 * The stats are the following five values for the original or
 * transformed arrays:
 * <ul><LI>slope of the regression line
 * =((n*&#8721;SC)-(&#8721;S*&#8721;C))
 * /((n*&#8721;S<sup>2</sup>)-(&#8721;S*&#8721;S)),
 * <LI> r<sup>2</sup> correlation coefficient
 * =(n*(&#8721;SC)-(&#8721;S*&#8721;C))
 * /&#8730;(((n*&#8721;Ssq)-(&#8721;S*&#8721;S))
 * ((n*&#8721;Csq)-((&#8721;C*&#8721;C))));
 * <LI> y intercept= (&#8721;C - (slope*&#8721;S))/n;,
 * <LI> inverse of prefactor FractalStatsF = Euler's e<sup>y-int</sup>
 * <LI> and standard error of estimate as
 * &#8730;((&#8721;C<sup>2</sup>-y-int*&#8721;C-slope*&#8721;SC)/(n-2))
 * </ul>
 * <h3>Needs:</h3><LI>not dependent</LI>
 *
 * The arrays are transformed differently depending on the
 * specific methods used.  For untransformed data, use the
 * {@link #PlainLinearRegression plain linear regression} method or the
 * {@link #PowerRegression power regression} method. For fractal
 * analysis, use {@link #FindDfStats Find Df stats method} which
 * uses the log of C and the log of 1/S  for passed arrays C and S.
 * Constructors call {@link #GetStats GetStats method}
 * to initialize variables for fractal analysis but other methods
 * must be called explicitly to return the proper statistics.
 *
 * <p> For futher information or to send comments, bugs, and feature requests
 * contact{@link <a href="mailto:akarpe@postoffice.csu.edu.au"> the author</a>}
 *
 * <p>file: FracStats.java</p>
 * <p>IDE: NetBeans 4.1</p>
 * @version FracLac v2.3 FracStats 2005
 * @author Audrey Karperien (akarpe01@postoffice.csu.edu.au),
 * Charles Sturt University
 * @since J2SKD1.5.0_03
 */

public class FracStats
{
    //////////////////////////////////////////////////////////////////////
    //////////////////////////// Variables  //////////////////////////////
    //////////////////////////////////////////////////////////////////////
    private float PlainsumSC=0,
    PlainsumS=0,
    PlainsumC=0,
    PlainsumSsq = 0,
    PlainsumCsq=0;
    private float[] oldcount;
    /**Float array of values for size in a box count*/
    private float[] oldsize;
    
   // private int correctedNumBoxes = 0;
    
    //private int oldnum;
    
  //  private float[] CSize;
    
  //  private float[] CCount;
    /**Slope of the linear regression line.
     * Is changed in {@link #GetStats get stats} to the
     * first element of the array returned by
     * {@link #PlainLinearRegression linear regression}.*/
    public float Pslope;
    /**Correlation coefficient squared or r<sup>2</sup>*/
    //private float Prsq;
    /**y-intercept*/
    //private float Pyint;
    /**Inverse of prefactor.  This variable is set in the
     *{@link #PlainLinearRegression} method, from index 3 (item 4)
     *of the returned array from {@link #PlainLinearRegression regression}
     *method.
     */
    //private float PF;
    //public float Pdf;
    /**Standard error returned by {@link #PlainLinearRegression linear regression}.*/
    //private float Pstderr;
    /**Fractal dimension or negative slope of log-log regression line
     * calculated in {@link #FindDfStats fractal} analysis method.*/
    public float df;
    /**Y intercept of log-log regression line, index 2 (item 3) returned by
     * {@link #FindDfStats fractal dimension} method.*/
    public float FractalStatsYint;
    /**FractalStatsF parameter or inverse of prefactor A in AX<sup>d</sup>
     * index 3 (element 4) returned by {@link #FindDfStats fractal dimension}
     * function.*/
    public float FractalStatsF;
    /**{@link #FindCompressed Compressed} fractal dimension.*/
    //private float cdf;
    /**{@link #FindCompressed Compressed} y-intercept.*/
    //private float cyint;
    /**When {@link #GetStats get stats} method is invoked,
     * this is set to index 3 (item 4)
     * from the {@link #FindCompressed compressed method}
     * .*/
    //private float cF;
    /**R<sup>2</sup> for log-log regression line, set from index 1 (item 2) from
     * {@link #FindDfStats fractal dimension} method when {@link #GetStats get stats}
     * method is invoked.*/
    //private float FractalStatsRsq;
    /**R squared for  {@link #FindCompressed Compressed} regression line.*/
    //private  float crsq;
    /**Slope of linear regression line.*/
    //private float ldf;
    /**Y-intercept of linear regression line.*/
    //private float lyint;
    /**R squared for linear regression line.*/
    //private  float lrsq;
    /**FractalStatsF parameter for linear regression line.*/
    //private float lF;
    /**Standard error of log-log regression line.*/
    //private float stderr;
    /**Standard error of linear regression line.*/
    //private float lstderr;
    /**Standard error compressed log-log regression line.*/
    //private   float cstderr;
    /**Linear regression line compressed slope.*/
    //private  float lcdf;
    /**R squared for linear
     * @link #FindCompressed Compressed} regression line.*/
    //private float lcrsq;
    /**Y-intercept for linear
     * {@link #FindCompressed Compressed} regression line.*/
    //private float lcyint;
    /**FractalStatsF parameter for linear
     * {@link #FindCompressed Compressed} regression line.*/
    //private float lcF;
    /**Standard error for
     * {@link #FindCompressed Compressed} linear regression line.*/
    //private float lcstderr;
    //////////////////////////////////////////////////////////////////////
    ////////////////////////////Constructors//////////////////////////////
    //////////////////////////////////////////////////////////////////////
    /**Constructor accepts arrays and calls {@link #GetStats GetStats} method.
     *@param C integer array for Y axis
     * (corresponds to counts for fractal analysis
     * @param S integer array for X axis
     * (corresponds to sizes for fractal analysis
     * @param originalNumSizes number of values to use in passed arrays
     */
    public FracStats (float[] C, int[] S, int originalNumSizes)
    {
        oldcount = new float [originalNumSizes];
        oldsize = new float [originalNumSizes];
        for (int w = 0; w<originalNumSizes; w++)
        {oldcount[w]=(float)C[w];
         oldsize[w]=(float)S[w];}
        
        //this.oldnum=originalNumSizes;
        GetStats (oldcount, oldsize, originalNumSizes);
        
    }
    /**Constructor .*/
    public FracStats ()
    {};
    
    /**Constructor accepts arrays and calls {@link #GetStats GetStats} method.
     * @param C float array (corresponds to counts for fractal analysis)
     * @param S float array (corresponds to sizes for fractal analysis)
     * @param originalNumSizes int for values to use in passed arrays
     */
    public FracStats (float[] C, float[] S, int originalNumSizes)
    {
        oldcount = new float [originalNumSizes];
        oldsize = new float [originalNumSizes];
        for (int w = 0; w<originalNumSizes; w++)
        {oldcount[w]=C[w];
            oldsize[w]=S[w];
        }
        
        //this.oldnum=originalNumSizes;
        GetStats (oldcount, oldsize, originalNumSizes);
        
    }
    /**Constructor accepts arrays and calls {@link #GetStats GetStats} method.
     * @param C int array (corresponds to counts for fractal analysis)
     * @param S float array (corresponds to sizes for fractal analysis)
     * @param originalNumSizes int for values to use in passed arrays
     */
    public FracStats (int[] C, float[] S, int originalNumSizes)
    {
        oldcount = new float [originalNumSizes];
        oldsize = new float [originalNumSizes];
        for (int w = 0; w<originalNumSizes; w++)
        {oldcount[w]=(float)C[w];
         oldsize[w]=(float)S[w];}
        
        //this.oldnum=originalNumSizes;
        GetStats (oldcount, oldsize, originalNumSizes);
        
    }

//    /**Constructor accepts arrays and calls {@link #GetStats GetStats} method.
//     * @param C float array (corresponds to counts for fractal analysis)
//     * @param S float array (corresponds to sizes for fractal analysis)
//     * @param originalNumSizes number of values to use in passed arrays
//     */
//    public FracStats (float[] C, float[] S, int originalNumSizes)
//    {
//        this.oldsize=S;
//        this.oldcount=C;
//        this.oldnum=originalNumSizes;
//        GetStats (oldcount, oldsize, originalNumSizes);
//        
//        
//    }
    //////////////////////////////////////////////////////////////////////
    ////////////////////////////  Methods   //////////////////////////////
    //////////////////////////////////////////////////////////////////////
    /**Calculates stats but returns nothing so
     * individual variables must be
     * accessed to get the stats.
     * Is automatically called by constructors but must be
     * called again for any changes. Calls
     * {@link #FindDfStats FindDfStats}, {@link #FindCompressed FindCompressed},
     * and {@link #InvLinearRegression LinearRegression} methods.
     * Variables set are <p>stats for power regression for
     * count and 1/size: <p>{@link #df slope or fractal dimension},
     * <p> {@link #FractalStatsRsq r<sup>2</sup>}, <p> {@link #FractalStatsYint y intercept},
     * <p> {@link #FractalStatsF prefactor},<p>  {@link #stderr standard error}, <p>
     *stats for array after horizontal slopes removed:
     * {@link #cdf slope or fractal dimension},
     * <p>  {@link #crsq r<sup>2</sup>}, <p> {@link #cyint y intercept},
     * <p> {@link #cF prefactor}, <p> {@link #cstderr standard error},
     * stats for linear regression: <p> {@link #ldf},
     * <p> {@link #lrsq},<p>  {@link #lyint},
     * <p> {@link #lF}, <p> {@link #lstderr}, <p> {@link #lcdf},
     * <p> {@link #lcrsq}, <p> {@link #lcyint},
     * <p> {@link #lcF}, <p> {@link #lcstderr}.
     *
     * @param ooldcount float array of counts
     * @param ooldsize integer array of sizes
     * @param ooriginalNumSizes integer for number of values to use
     */
    private void GetStats (float[] ooldcount, float[] ooldsize, int ooriginalNumSizes)
    {
        float [] reg = FindDfStats (ooldcount, ooldsize, ooriginalNumSizes);
        df= reg[0];
        //FractalStatsRsq=reg[1];
        FractalStatsYint=reg[2];
        FractalStatsF=reg[3];
        //stderr=reg[4];
        //float [] comp = FindCompressed (ooldcount, ooldsize, ooriginalNumSizes);
        //cdf= comp[0];
       // crsq=comp[1];
       // cyint=comp[2];
        //cF=comp[3];
       // cstderr=comp[4];
        //float [] linear
        //= InvLinearRegression (ooldcount, ooldsize, ooriginalNumSizes);
        //ldf=linear[0];
       // lrsq=linear[1];
        //lyint=linear[2];
       // lF=linear[3];
       // lstderr=linear[4];
        //float [] lcompress = InvLinearRegression (CCount, CSize, correctedNumBoxes);
       // lcdf=lcompress[0];
       // lcrsq=lcompress[1];
       // lcyint=lcompress[2];
       // lcF=lcompress[3];
       // lcstderr=lcompress[4];
        float[] regularstats = PlainLinearRegression (ooldcount, ooldsize, ooriginalNumSizes);
        Pslope=regularstats[0];
       // Prsq=regularstats[1];
       // Pyint=regularstats[2];
       // PF=regularstats[3];
        //Pstderr=regularstats[4];
    }
    
    
    
    
    
    
    
    /** Removes areas of horizontal slope by retaining only whichever value
     *in an interval
     *of equal counts (testarray) had the smallest value for box size (Sizes),
     *and returns
     * {@link #FindDfStats array} using the corrected set of arrays. Is usually
     *called by an overloaded version of itself that received integer data.
     *
     * @param testarray is the first float array to assess (e.g., of counts
     * of boxes containing pixels in a box count)
     * @param Sizes is an integer array, the second array to
     * assess in calculating regression line
     * @param oldNumSizes int for the number of entries to assess
     * in the passed arrays
     * @return float array from {@link #FindDfStats FindDfStats method} */
    /*
    private float[] FindCompressed (float[] testarray,
            float[] Sizes, int oldNumSizes)
    {
        correctedNumBoxes = 1;
        float []c = new float [oldNumSizes];
        float []s = new float [oldNumSizes];
        s[0]=Sizes[0];
        c[0]=testarray[0];
        for (int q=1; q<oldNumSizes; q++)
            //for (int q=NumSizes-1;q>=0; q--)
        {
            boolean proceed = false;
            
            if (testarray[q]!=testarray[q-1])proceed=true;
            
            if (proceed==true)
            {
                s[correctedNumBoxes]=Sizes[q];
                c[correctedNumBoxes]=testarray[q];
                correctedNumBoxes++;
            }
            
        }
        CSize=new float [correctedNumBoxes];
        CCount = new float [correctedNumBoxes];
        for (int i = 0; i < correctedNumBoxes; i++)
        {
            CSize[i]=s[i];
            CCount[i]=c[i];
        }
        return FindDfStats (CCount, CSize, correctedNumBoxes);
        
    }
    */
    
    /**
     * When called in fractal analysis, finds the fractal dimension
     * and related statistics from box counting data gathered from
     * a pattern.  The passed arrays are usually the number or count of covering
     * objects at each size of covering objects that was required to
     * efficiently cover the pattern being analyzed.
     * The returned array holds power law
     * {@link #CalculateStats regression} statistics typically used in fractal
     * analysis, calculated
     * from the log of the passed Counts array and the log of
     * the inverse
     * of the Sizes area (i.e., 1/Sizes). Thus, FindDfStats sums and transforms
     * the data and passes the {@link #CalculateStats regression} method the
     * following values:
     * <ul>
     * <LI>&Sigma;SC = &Sigma;(ln (Sizes[q]<sup>-1</sup>)*ln Counts[q])</LI>
     * <LI>&Sigma;S = &Sigma;ln (Sizes[q]<sup>-1</sup>)</LI>
     * <LI>&Sigma;C = &Sigma;ln Counts[q]</LI>
     * <LI>&Sigma;C<sup>2</sup> = &Sigma;ln (Counts[q]<sup>2</sup>)</LI>
     * <LI>&Sigma;S<sup>2</sup> = &Sigma;(ln (Sizes[q]<sup>-1</sup>)<sup>2</sup>)</LI>
     * </ul>
     *
     * @param Counts array of floats
     * @param Sizes array of integers; 1/Sizes[i] is used
     * @param NumSizes an integer for the number of values to use
     * from the passed arrays
     * @return float array with 5 {@link #CalculateStats statistics}*/
    private float[] FindDfStats (float[] Counts, float[] Sizes, int NumSizes)
    {  //takes an array for box sizes and an array for Counts and
        //the number of box sizes to check and calculates stats using those arrays*/
        
        float n=(float)NumSizes;
        float DsumSC=0, DsumS=0, DsumC=0, DsumSsq = 0, DsumCsq=0;
        
        for (int q=0; q<NumSizes; q++)
        {//go through array and sum values for regression line*/
            
            /////SUM THE LOG OF THE COUNT*THE LOG OF THE SIZE\
            ////use the scale factor, calculated as the
            ////box size given divided by the largest size
            
            DsumSC = DsumSC
            + (float)(Math.log (1.0f/(float)Sizes[q])
            *Math.log ((float)Counts[q]));
            
            ///SUM THE LOG OF THE SIZE
            
            DsumS = DsumS + (float)Math.log (1.0f/Sizes[q]);
            
            //SUM THE LOG OF THE COUNTS
            
            DsumC = DsumC + (float)Math.log (Counts[q]);
            
            //SUM THE LOG OF COUNTS TIMES LOG OF COUNTS
            
            DsumCsq
            =DsumCsq+(float)(Math.log (Counts[q])*Math.log (Counts[q]));
            
            //SUM THE LOG OF SIZE TIMES LOG SIZE
            
            DsumSsq = DsumSsq
            +(float)(Math.log (1.0f/Sizes[q])*Math.log (1.0/Sizes[q]));
        }
        
        return CalculateStats (
        DsumSC,
        DsumS,
        DsumC,
        DsumSsq,
        DsumCsq,
        n);
        
        
    }
   
    
     
    
   
    /**Returns {@link #CalculateStats stats}
     * array of power law regression data, using
     * log of Counts (Y) array and log of Sizes (X) array.
     *
     * @param Counts array of floats
     * @param Sizes array of integers
     * @param NumSizes an integer for the number of values to use
     * from the passed arrays
     * 
     * @return float array with 5 {@link #CalculateStats statistics}*/
    /*
    private float[] PowerRegression (float[] Counts, float[] Sizes, int NumSizes)
    { 
        float n=(float)NumSizes;
        float DsumSC=0, DsumS=0, DsumC=0, DsumSsq = 0, DsumCsq=0;
        for (int q=0; q<NumSizes; q++)
        {
            /////SUM THE LOG OF THE COUNT*THE LOG OF THE SIZE\
            DsumSC
            = DsumSC
            + ((float)Math.log (Sizes[q])*((float)Math.log (Counts[q])));
            ///SUM THE LOG OF THE SIZE
            DsumS = DsumS + ((float)Math.log (Sizes[q]));
            //SUM THE LOG OF THE COUNTS
            DsumC = DsumC + ((float)Math.log (Counts[q]));
            //SUM THE LOG OF COUNTS TIMES LOG OF COUNTS
            DsumCsq
            =DsumCsq+(((float)Math.log (Counts[q]))
            *((float)Math.log (Counts[q])));
            //SUM THE LOG OF SIZE TIMES LOG SIZE
            DsumSsq
            = DsumSsq + ((float)Math.log (Sizes[q])*((float)Math.log (Sizes[q])));
        }
        return CalculateStats (DsumSC,
        DsumS,
        DsumC,
        DsumSsq,DsumCsq,
        n);
        
        
    }
    */
    
    
    
    
    
    
    /**Returns array of statistics. Operates on the inverse of Sizes
     * array.
     * @param Counts float array for x axis (e.g., number of boxes that
     * contained pixels in fractal analysis)
     * @param Sizes float array for y axis (e.g., the corresponding
     * array of box sizes)
     * @param NumSizes integer for the number of elements to
     * use in both arrays
     * @return float array with 5 {@link #CalculateStats statistics}
     */
    /*
    private float[] InvLinearRegression (float[] Counts, float[] Sizes, int NumSizes)
    { 
        float n=(float)NumSizes;
        float DsumSC=0, DsumS=0, DsumC=0, DsumSsq = 0, DsumCsq=0;
        for (int q=0; q<NumSizes; q++)
        {
            /////SUM THE COUNT*THE SIZE
            DsumSC
            = DsumSC + (float)((1.0f/Sizes[q])*Counts[q]);
            ///SUM THE SIZE
            DsumS = DsumS + (float)(1.0f/Sizes[q]);
            //SUM THE COUNTS
            DsumC = DsumC + (float)(Counts[q]);
            //SUM THE COUNTS TIMES COUNTS
            DsumCsq
            =DsumCsq+(float)((Counts[q])*(Counts[q]));
            //SUM THE SIZE TIMES SIZE
            DsumSsq
            = DsumSsq + (float)((1.0f/Sizes[q])*(1.0f/Sizes[q]));
        }
        return CalculateStats (DsumSC,
        DsumS,
        DsumC,
        DsumSsq,
        DsumCsq,
        n);
    }
    */
    
    /***************************************************************/
    /**Returns array of regression statistics. Operates on the passed arrays.
     *
     * @param        Y float array for x axis (e.g., count of boxes that
     * contained pixels in fractal analysis)
     * @param       X float array for y axis (e.g., the corresponding
     * array of box sizes)
     * @param        Num integer for the number of elements to
     * use in both arrays
     * @return           float array with 5 {@link #CalculateStats statistics}
     */
    public float[] PlainLinearRegression (float[] Y, float[] X, int Num)
    {  /*takes an array for box sizes and an array for Counts and
     *the number of box sizes to check and calculates stats using those arrays*/
        float n=(float)Num;
        PlainsumSC=0;
        PlainsumS=0;
        PlainsumC=0;
        PlainsumSsq = 0;
        PlainsumCsq=0;
        for (int q=0; q<Num; q++)
        {/*go through array and sum values for regression line*/
            /////SUM THE COUNT*THE SIZE
            PlainsumSC
            = PlainsumSC + (X[q]*Y[q]);
            ///SUM THE SIZE
            PlainsumS = PlainsumS + (X[q]);
            //SUM THE COUNTS
            PlainsumC = PlainsumC + (Y[q]);
            //SUM THE COUNTS TIMES COUNTS
            PlainsumCsq
            =PlainsumCsq+(Y[q]*Y[q]);
            //SUM THE SIZE TIMES SIZE
            PlainsumSsq
            = PlainsumSsq + (X[q]*X[q]);
        }
        
        return CalculateStats (PlainsumSC,
        PlainsumS,
        PlainsumC,
        PlainsumSsq,
        PlainsumCsq,
        n);
    }
    
    /********************************************************************/
    /**Returns an array holding the slope of the regression line,
     * the r<sup>2</sup>,
     * the y-intercept, the prefactor<sup>-1</sup> (prefactor is A
     * in y=Ax<sup>b</sup>) for power law regressions, and the standard error
     * for a regression line calculated from the passed values.
     * This method is called by this class's other methods that
     * prepare (for example, transform and sum)the original arrays.
     *
     *<UL>
     * <LI>
     * CALCULATE THE SLOPE OF THE REGRESSION LINE
        <li>
     *  b=
        ((n*&Sigma;SC)-(&Sigma;S*&Sigma;C))
        /((n*&Sigma;S<sup>2</sup>)-(&Sigma;S*&Sigma;S));
        </li>
        </LI>
        <li>CALCULATE CORRELATION COEFFICIENT OF REGRESSION LINE
       <li>correl= (n*(&Sigma;SC)-(&Sigma;S*&Sigma;C))
        /sqrt (((n*&Sigma;S<sup>2</sup>)-(&Sigma;S*&Sigma;S))*
        *((n*&Sigma;C<sup>2</sup>)-((&Sigma;C*&Sigma;C))));
       </li>
     * <li>correl= correl<sup>2</sup>;
     *</li></LI>
        
        <LI>CALCULATE Y INTERCEPT OF REGRESSION LINE
        <li>yint
        = (&Sigma;C-(b*&Sigma;S))/n
       </li></LI>
     <LI>CALCULATE THE PREFACTOR FOR THE REGRESSION LINE
       <li>A=1/e<sup>y-intercept</sup></li>
     * <li>
        for a power law: y=Ax<sup>b</sup></LI>
        </LI></li>
     <LI>CALCULATE STANDARD ERROR
     *<li>se=sqrt ((&Sigma;C<sup>2</sup>-y-intercept*&Sigma;C-b*&Sigma;SC)/(n-2))
     *</li></li></UL>
     *@see      #FindDfStats
     *@param        DsumSC float for sum of all S times C array
     *@param        DsumS float for sum of all S array
     *@param        DsumC float for sum of all C array
     *@param        DsumSsq float for sum of all S<sup>2</sup>
     *@param        DsumCsq float for sum of all C<sup>2</sup>
     *@param        n float for number of values that were summed in one array
     *@return          float array holding slope, correlation r<sup>2</sup>,
     *          y-intercept,
     *          prefactor's inverse, and standard error for regression line.
     */
    private float [] CalculateStats (
    float DsumSC,
    float DsumS,
    float DsumC,
    float DsumSsq,
    float DsumCsq,
    float n)
    {
        float [] fivestats=new float[5];
        
        
        //CALCULATE THE SLOPE OF THE REGRESSION LINE
        float b=
        ((n*DsumSC)-(DsumS*DsumC))
        /((n*DsumSsq)-(DsumS*DsumS));
        fivestats[0]=b;//-1*b;
        
        //CALCULATE CORRELATION COEFFICIENT OF REGRESSION LINE
        float correl=(n*(DsumSC)-(DsumS*DsumC))
        /(float)Math.sqrt (((n*DsumSsq)-(DsumS*DsumS))
        *((n*DsumCsq)-((DsumC*DsumC))));
        fivestats[1] = correl*correl;
        
        //CALCULATE Y INTERCEPT OF REGRESSION LINE
        float ayint
        = (DsumC-(b*DsumS))/n;
        /*y intercept for linear regression by least squares*/
        //System.out.println(ayint);
        fivestats[2]=ayint;
        //CALCULATE THE PREFACTOR FOR THE REGRESSION LINE
        //IF THIS WERE A POWER REGRESSION
        fivestats[3]=1f/(float)(Math.exp (ayint));//Prefactor A = e to the FractalStatsYint
        //for a power law: y=Ax^Df
        //standarderror
        fivestats[4]=(float)Math.sqrt ((DsumCsq-ayint*DsumC-b*DsumSC)/(n-2f));
        
        return fivestats;
    }
    
    
    
}

